package com.zhiying.web.util;

import io.jsonwebtoken.CompressionCodecs;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

public class JwtUtil {
    public static String getTokenContent(String subject) {
        Date now = new Date();
        Date oneWeek = new Date(now.getTime() + 1000*60*10080);
        String token = Jwts.builder()
                .setSubject(subject)
                .compressWith(CompressionCodecs.DEFLATE)
                .signWith(SignatureAlgorithm.HS256, Constants.SECRET_KEY).setExpiration(oneWeek)
                .compact();
        return token;
    }

//    public static Claims getClaims(String token) {
//        try {
//            Claims claims = Jwts
//                    .parser()
//                    .setSigningKey(Constants.SECRET_KEY.getBytes())
//                    .parseClaimsJws(token)
//                    .getBody();
//            return claims;
//        } catch(ExpiredJwtException e) {
//            return null;
//        }
//    }


}
